//
//  WFServiceRequest.m
//  WisdomFarm
//
//  Created by sky on 2018/2/27.
//  Copyright © 2018年 sky. All rights reserved.
//

#import "WFServiceRequest.h"
#import "WFStore.h"

@implementation WFServiceRequest

- (void)startWithBlock:(MZRequestBlock)block {
    NSDictionary *parameters = @{
                                 @"description" : self.desc ?: @"",
                                 @"latitude" : @([WFCacheStore sharedCacheStore].currentLocation.coordinate.latitude),
                                 @"longitude" : @([WFCacheStore sharedCacheStore].currentLocation.coordinate.longitude),
                                 @"type" : @(self.type),
                                 };
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:@"http://smart.zjmb.gov.cn/ZhnyqxImageUpload.aspx"
       parameters:parameters
constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
    [self.images enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSData *data = UIImageJPEGRepresentation(obj, 0.8);
        NSString *name = self.imageNames[idx];
        [formData appendPartWithFileData:data name:@"image" fileName:name mimeType:@"image/jpeg"];
    }];
}
         progress:nil
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              block(nil, nil);
          } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              block(nil, error);
          }];
    
}

@end
